<?php
namespace App\Http\Controllers;
use App\Models\Like;
use App\Models\Note;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LikeController extends Controller
{
    public function toggle(Request $request, $noteId)
    {
        $user = Auth::user();
        $note = Note::findOrFail($noteId);

        $like = Like::where('user_id', $user->id)->where('note_id', $noteId)->first();

        if ($like) {
            $like->delete();
            return response()->json(['liked' => false]);
        }

        Like::create(['user_id' => $user->id, 'note_id' => $noteId]);
        return response()->json(['liked' => true]);
    }
}